package com.dg11185.nearshop.net.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class CountByAreaResponse {

    public NetStatus status = null;

    public List<AreaCount> areaCounts = null;

    public CountByAreaResponse() {
        areaCounts = new ArrayList<CountByAreaResponse.AreaCount>();
    }

    public void parseJson(String response){
        System.out.println(response);
        try {
            JSONObject jsonObject = new JSONObject(response);
            status = NetStatus.getStatus(jsonObject.optString("status"));

            if (!jsonObject.isNull("areaCountList")) {
                 JSONArray array = jsonObject.optJSONArray("areaCountList");
                 for(int a=0; a<array.length(); a++){
                     JSONObject object = array.getJSONObject(a);
                     AreaCount areaCount = new AreaCount();
                     areaCount.areaNum = object.optString("areaNum");
                     areaCount.areaName = object.optString("areaName");
                     areaCount.countNum = object.optString("countNum");
                     areaCounts.add(areaCount);
                 }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    
    }

    public static class AreaCount {
        public String areaNum = "";

        public String areaName = "";

        public String countNum = "";
    }

}
